package com.lijinjiang.graphics;

import com.lijinjiang.constant.Colors;

import javax.swing.*;
import java.awt.*;

/**
 * @Description 上一个图标
 * @Author lijinjiang
 * @Date 2024-12-30 10:52
 */
public class JPreviousIcon implements Icon {

    private int width;
    private int height;

    private final int[] xPoints = new int[3];
    private final int[] yPoints = new int[3];

    private final boolean doubleArrow;
    private final boolean enabled;

    public JPreviousIcon(int width, int height, boolean doubleArrow, boolean enabled) {
        setDimension(width, height);
        this.doubleArrow = doubleArrow;
        this.enabled = enabled;
    }

    public int getIconWidth() {
        return width;
    }

    public int getIconHeight() {
        return height;
    }

    public void setDimension(int width, int height) {
        this.width = width;
        this.height = height;
    }

    public void paintIcon(Component c, Graphics g, int x, int y) {
        if (enabled) {
            g.setColor(Colors.FG_TOP_BUTTON);
        } else {
            g.setColor(Colors.FG_TOP_BUTTON_DISABLED);
        }
        if (doubleArrow) {
            xPoints[0] = x;
            yPoints[0] = y + (height / 2);
            xPoints[1] = x + (width / 2);
            yPoints[1] = y - 1;
            xPoints[2] = x + (width / 2);
            yPoints[2] = y + height;
            g.fillPolygon(xPoints, yPoints, 3);
            xPoints[0] = x + (width / 2);
            yPoints[0] = y + (height / 2);
            xPoints[1] = x + width;
            yPoints[1] = y - 1;
            xPoints[2] = x + width;
            yPoints[2] = y + height;
            g.fillPolygon(xPoints, yPoints, 3);
        } else {
            xPoints[0] = x;
            yPoints[0] = y + (height / 2);
            xPoints[1] = x + width;
            yPoints[1] = y - 1;
            xPoints[2] = x + width;
            yPoints[2] = y + height;
            g.fillPolygon(xPoints, yPoints, 3);
        }
    }
}
